{%  extends 'base.html' %}
{% load static %}
{% block content %}
<div class="layui-tab" lay-filter="demo" lay-allowclose="true">
  <ul class="layui-tab-title">
    <li class="layui-this" lay-id="11">更新插件</li>
  </ul>
  <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
<div class="demoTable">
  搜索：
  <div class="layui-inline">
    <input class="layui-input" name="id"  autocomplete="off">
  </div>
  <button class="layui-btn" id="demoReload" data-type="reload">搜索</button>
</div>
<table class="layui-hide" id="LAY_table_plugin" lay-filter="LAY_table_plugin"></table>
    </div>
  </div>
</div>

{% endblock %}

{% block js %}

<script>
layui.use('table', function(){
  var table = layui.table;
  //方法级渲染
  table.render({
    elem: '#LAY_table_plugin'
    ,url: '/deploy/jsondata/'
    ,cols: [[{field:'id', title: 'ID', width:80, sort: true, fixed: true}
      ,{field:'name', title: '插件名', width:200}
      ,{field:'version', title: '版本', width:150}
      // ,{field:'log', title: '变更记录', width:200}
      ,{field:'env', title: '环境', width:200,style:'background-color: #009688; color: #fff;'}
      ,{field:'do', title: '操作', toolbar: '#barDemo',width:300}
    ]]
    ,id: 'testReload'
    ,page: true
    ,height: 600
  });
//更新插件
  table.on('tool(LAY_table_plugin)', function(obj){
    var name = obj.data.name; //获得当前行数据
    var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      if(layEvent === 'update') { //审核
        var loadix =layer.load({offset: "180px",shade:  [0.1,'#fff']});
        $.ajax({
          type: 'POST',
          url: '/deploy/update_plugin',
          dataType: 'json',
          data: name,
          success: function (res) {
            if (res.code ==200) {
              layer.close(loadix);
              layer.msg(res.msg, {
                offset: '180px'
                , icon: 6
                , time: 3000
              });
              table.reload('LAY_table_plugin');
            } else {
              layer.close(loadix);
              layer.msg(res.msg, {
                offset: '180px'
                , icon: 0
                , time: 3000
              });
            }
          },
        });
      }

      else if(layEvent === 'log') {
               $.ajax({
          type: 'POST',
          url: '/deploy/check_log',
          dataType: 'json',
          data: name,
          success: function (res) {
            if (res.code ==200) {
             layer.open({
                  type: 1,
                  skin: 'layui-layer-rim', //加上边框
                  area: ['700px', '600px'], //宽高
                  content: res.msg
                });

              // layer.msg(res.msg, {
              //   offset: '180px'
              //   , icon: 6
              //   , time: 3000
              // });
              table.reload('LAY_table_plugin');
            }
          },
        });
  }
});

  // var $ = layui.$, active = {
  //   reload: function(){
  //     var demoReload = $('#demoReload');
  //
  //     //执行重载
  //     table.reload('testReload', {
  //       page: {
  //         curr: 1 //重新从第 1 页开始
  //       }
  //       ,where: {
  //         key: {
  //           id: demoReload.val()
  //         }
  //       }
  //     }, 'data');
  //   }
  // };

   $('#demoReload').click(function (){
  var inputVal = $('.layui-input').val()
  table.reload('testReload', {
  url: '/deploy/searchplugin'
  ,request: {
   pageName: 'page' //页码的参数名称，默认：page
   ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
  }
  ,where: {
   query : inputVal
  }
  ,page: {
   curr: 1
  }
  });
 })




  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});


</script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="update">更新</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="log">更新日志</a>
</script>

{% endblock %}